package main

import "fmt"

func removeElement(nums []int, val int) int {
	a := 0
	b := 0
	//nums2 := make([]int, len(nums))
	////fmt.Println(nums2)
	//for i := 0; i < len(nums); i++ {
	//	if nums[i] != val {
	//		nums2[i-a] = nums[i]
	//		//fmt.Println(nums2)
	//	}
	//	if nums[i] == val {
	//		a++
	//	}
	//}
	nums2 := nums
	//fmt.Println(nums2)
	for i := 0; i < len(nums2); i++ {
		if nums2[i] != val {
			nums[i-a] = nums2[i]
			b++
			//fmt.Println(nums2)
		}
		if nums2[i] == val {
			a++
		}
	}

	//fmt.Println("1:   ", nums)
	////nums = nums2
	//fmt.Println("2:   ", nums2)
	//fmt.Println("1:   ", nums)
	return b

}

func main() {
	var nums []int
	nums = []int{0, 1, 2, 2, 3, 0, 4, 2}
	b := removeElement(nums, 2)
	fmt.Println("nums: ", b)
	fmt.Println(nums)
	//nums = []int{0, 1, 2, 2, 3, 0, 4, 2}
	//fmt.Println("nums: ", nums, removeElement(nums, 2))
	//nums = []int{}
	//fmt.Println("nums: ", nums, removeElement(nums, 3))
}
